package com.nineclock.system.controller;

import com.nineclock.api.system.controller.SysCompanyControllerApi;
import com.nineclock.common.entity.Result;
import com.nineclock.dto.*;
import com.nineclock.pojo.SysCompany;
import com.nineclock.system.service.SysCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
@RestController
@RequestMapping("/company")
public class SysCompanyController implements SysCompanyControllerApi {
    @Autowired
    private SysCompanyService sysCompanyService;
// 根据用户id查询所对应的企业列表
    @GetMapping("/list/{userId}")
    @Override
    public Result<List<SysCompanyDTO>> findCompanyByUserId(@PathVariable("userId") long userId) {
        List<SysCompanyDTO> companyDTOS = sysCompanyService.findCompanyByUserId(userId);
        return Result.success(companyDTOS);
    }

    // 查询企业基本信息
    @GetMapping
    @Override
    public Result<SysCompanyDTO> findCompanyInfo() {
        SysCompanyDTO sysCompanyDTO = sysCompanyService.findCompanyInfo();
        return Result.success(sysCompanyDTO);
    }

    // 上传企业Logo
    @PostMapping("/uploadOSS")
    @Override
    public Result<String> uploadOSS(MultipartFile file) {
        String url = sysCompanyService.uploadOSS(file);
        return Result.success(url);
    }

    // 更新企业基本信息
    @PutMapping
    @Override
    public Result updateCompanyInfo(@RequestBody SysCompanyDTO sysCompanyDTO) {
        sysCompanyService.updateCompanyInfo(sysCompanyDTO);
        return Result.success();
    }
        // 获取组织下所有员工
    @GetMapping("/getCurrentAdmin")
    @Override
    public Result<SysCompanyUserDTO> findCompanyUserAdmin() {
      SysCompanyUserDTO sysCompanyUserDTO =  sysCompanyService.findCompanyUserAdmin();
        return Result.success(sysCompanyUserDTO);
    }

    // 更改管理员
    @PostMapping("/config/admin")
    @Override
    //public Result updateAdmin(@RequestBody String code, @RequestBody Integer userId)
    public Result updateAdmin(@RequestBody SysChangeMainManagerDTO sysChangeMainManagerDTO) {
        sysCompanyService.updateAdmin(sysChangeMainManagerDTO);
        return Result.success();
    }

    // 根据关键字查询企业列表
    @GetMapping("/list")
    @Override
    public Result<List<SysCompanyDTO>> findCompanyByKeyword(String keyword) {
        List<SysCompanyDTO> sysCompanyList = sysCompanyService.findCompanyByKeyword(keyword);
        return Result.success(sysCompanyList);
    }

    // 加入企业申请
    @PostMapping("/applyJoinCompany")
    @Override
    public Result applyJoinCompany(@RequestBody SysApplyJoinCompanyUserDTO joinCompanyUserDTO) {
        sysCompanyService.applyJoinCompany(joinCompanyUserDTO);
        return Result.success();
    }

    // 审核加入企业
    @PostMapping("/allowedJoinCompany")
    @Override
    public Result allowedJoinCompany(SysAllowedJoinCompanyUserDTO sysAllowedJoinCompanyUserDTO) {
        sysCompanyService.allowedJoinCompany(sysAllowedJoinCompanyUserDTO);
        return Result.success();
    }
}
